package com.mujin.keji.collectionsystem.module.updata.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.ClickFileListener;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.module.outboundtask.views.BoundDetailActivity;
import com.mujin.keji.collectionsystem.module.updata.dto.ShowVisitUserDto;
import com.mujin.keji.collectionsystem.module.updata.dto.VisitUserDto;
import com.mujin.keji.collectionsystem.utils.FileUtil;
import com.mujin.keji.collectionsystem.utils.ImageUtils;

import java.util.List;


/**
 * 上传单个案件适配器列表
 *
 * @author weishixiong
 * @Time 2018-05-8
 */

public class UpFileListAdapter extends RecyclerView.Adapter<UpFileListAdapter.ViewHolder> {
    private Activity mContext;
    private List<VisitUserDto> datas;//需要展示的集合
    private ClickFileListener listener;

    public UpFileListAdapter(Activity context, List<VisitUserDto> datas, ClickFileListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_up_file_list, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvName.setText(datas.get(position).getTime());
        if ("1".equals(datas.get(position).getFileType())) {
            if (datas.get(position).isPlaying()) {
                ImageUtils.loadImage(mContext, R.drawable.image_start, holder.ivHead);
                //holder.ivRecordPlay.setVisibility(View.VISIBLE);
                holder.ivRecordPlay.setImageResource(R.drawable.image_start_record);
            } else {
                holder.ivHead.setImageResource(R.drawable.image_record_head);
                //holder.ivRecordPlay.setVisibility(View.VISIBLE);
                holder.ivRecordPlay.setImageResource(R.drawable.image_record_play);
            }

        } else if ("2".equals(datas.get(position).getFileType())) {
            //holder.tvName.setText("外访照片");
            holder.ivHead.setImageResource(R.drawable.image_file_head);
            // holder.ivRecordPlay.setVisibility(View.GONE);
            holder.ivRecordPlay.setImageResource(R.drawable.image_arrow);
        }
        holder.tvDate.setText(datas.get(position).getFileTime());
        holder.tvAdress.setText(datas.get(position).getFileAdress());
        holder.tvSize.setText(FileUtil.getAutoFileOrFilesSize(datas.get(position).getFile()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.clickFile(datas.get(position));
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvName;
        private TextView tvDate;
        private TextView tvSize;
        private TextView tvAdress;
        private ImageView ivHead;
        private ImageView ivRecordPlay;
        private View itemView;

        public ViewHolder(final View itemView) {
            super(itemView);
            this.itemView = itemView;
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvDate = (TextView) itemView.findViewById(R.id.tv_date);
            tvSize = (TextView) itemView.findViewById(R.id.tv_size);
            tvAdress = (TextView) itemView.findViewById(R.id.tv_adress);
            ivHead = (ImageView) itemView.findViewById(R.id.iv_head);
            ivRecordPlay = (ImageView) itemView.findViewById(R.id.iv_record_play);

        }

    }
}
